package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 

    public DvdUI()
    {
        dvdCtr=new DVDCtr();
    }

    public void start()
    {
        dvdMenu();
    }

    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise =   writeDVDMenu();
            if (choise == 1)
            {
                findDVD();
            }
            else{if(choise == 2){
                    createDVD();
                }
                else{
                    if(choise == 3){
                        createCopy();
                    }
                    else{
                        if(choise == 4){
                            deleteDVD();
                        }
                        else{
                            if(choise == 5){
                                listAllDvds();
                            }
                            else{
                                if(choise == 6){
                                    deleteCopy();
                                }
                                else{
                                    if(choise == 7){
                                    updateDVD();
                                }
                                else{
                                    if(choise == 8){
                                    updateCopy();
                                }
                                else{
                                    exit = true;
                                }//end else
                                }//end else
                                }//end else
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else

        }//end while
    }

    private int writeDVDMenu()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** DVD Menu ***");
        System.out.println(" (1) Show DVD information");
        System.out.println(" (2) Create DVD");
        System.out.println(" (3) Create Copy");
        System.out.println(" (4) Delete DVD");
        System.out.println(" (5) Show current DVD list");
        System.out.println(" (6) Delete Copy");
        System.out.println(" (7) update DVD");
        System.out.println(" (8) update Copy");
        System.out.println(" (9) Return");
        System.out.print("\n Make your choise: ");

        int choise = keyboard.nextInt();
        return choise;
    }

    private int inputDVDId()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD id: ");
        int id = keyboard.nextInt();
        return id;
    }

    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }

    private String inputArtist()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD artist: " );
        String artist = keyboard.nextLine();
        return artist;
    }

    private String inputReleaseDate()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD releasedate: " );
        String releaseDate = keyboard.nextLine();
        return releaseDate;
    }

    private String inputCopySerialNumber()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the copy number: ");
        String serialNumber = keyboard.nextLine();
        return serialNumber;
    }
    
    private String inputPurchaseDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the purchase date: ");
        String purchaseDate = keyboard.nextLine();
        return purchaseDate;
    }
    
    private double inputPurchasePrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the purchase price: ");
        double purchaseDate = keyboard.nextDouble();
        return purchaseDate;
    }
    
    

    //there is need for more methods to read information about DVDs
    //and methods to display the information

    public String findDVD()
    {     
        int id = inputDVDId(); // id = input from scanner.
        // is to be changed when the DVD controller is completed
        // String dvd = String.valueOf(dvdCtr.findDVD(id));// returns dvd object of type DVD and translates into string
        Scanner keyboard = new Scanner(System.in);
        dvdCtr.findDVD(id).printInfo();
        String returnToMenu=keyboard.nextLine();
        return returnToMenu;
        
    }

    private void createDVD()
    {
        int id=inputDVDId();
        String title=inputTitle();
        String artist=inputArtist();
        String releaseDate=inputReleaseDate();
        dvdCtr.createDVD(id, title, artist, releaseDate);

        //         DVD dvd=dvdCtr.findDVD(id);
        //         dvdCtr.addDVD(dvd);
    }
    private void deleteDVD()
    {
        int id=inputDVDId();
        dvdCtr.deleteDVD(id);
    }

    private void createCopy()
    {
        int id=inputDVDId();
        String serialNumber=inputCopySerialNumber();
        String purchaseDate=inputPurchaseDate();
        double purchasePrice=inputPurchasePrice();
        dvdCtr.createCopy(id, serialNumber, purchaseDate, purchasePrice);
    }
    
    private void deleteCopy()
    {
        int id=inputDVDId();
        String serialNumber=inputCopySerialNumber();
        dvdCtr.deleteCopy(id, serialNumber);
    }

    private String listAllDvds()
    {
        Scanner keyboard = new Scanner(System.in);
        dvdCtr.listAllDvds();
        String returnToMenu=keyboard.nextLine();
        return returnToMenu;
        
        //dvdCtr.listAllDvds();
    }
    
    private void updateDVD()
    {
        int id=inputDVDId();
        String title=inputTitle();
        String artist=inputArtist();
        String releaseDate=inputReleaseDate();
        
        dvdCtr.updateDVD(id, title, artist, releaseDate);
    }
    private void updateCopy()
    {
        int id=inputDVDId();
        String serialNumber=inputCopySerialNumber();
        String purchaseDate=inputPurchaseDate();
        double purchasePrice=inputPurchasePrice();
        dvdCtr.updateCopy(id, serialNumber, purchaseDate, purchasePrice);
    }
    
}